package com.handpay.nocardpay.baselibrary.bill.model.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TableLayout;
import android.widget.TextView;

import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.bill.model.bean.BillBean;
import com.handpay.nocardpay.baselibrary.commbase.model.adapter.BaseListViewAdapter;
import com.handpay.nocardpay.baselibrary.commbase.model.adapter.BaseListViewViewHolder;
import com.handpay.nocardpay.baselibrary.utils.BillConstant;
import com.handpay.nocardpay.baselibrary.utils.CommonUtils;

import java.util.List;

/**
 * Created by sxshi on 2017/8/16.
 */

public class QueryBillAdapter extends BaseListViewAdapter<BillBean.ListBean> {

    public QueryBillAdapter(Context context) {
        super(context);
    }

    public QueryBillAdapter(Context context, List<BillBean.ListBean> mLists) {
        super(context, mLists);
    }

    @Override
    public int getLayoutId(int postion) {
        return R.layout.item_bill;
    }

    @Override
    public void convert(BaseListViewViewHolder holder, BillBean.ListBean listBean, int position) {
        String mTranstime = listBean.getTransTime();
        int mStatus = listBean.getStatus();
        String mSerialNumber = listBean.getTransSN();
        int mTradeType = listBean.getTradeType();
        String mCardNoOut = listBean.getTransAccount();
        double mTotal = listBean.getTotal();

        TextView transtime = holder.getView(R.id.transTime);
        TextView transStatus = holder.getView(R.id.transStatus);
        TextView trTransSn = holder.getView(R.id.transSn);
        TextView tr_trans_type = holder.getView(R.id.trTrans_mode);
        TextView cardNoOut = holder.getView(R.id.cardNoOut);
        TextView tv_total = holder.getView(R.id.tv_total);
        TableLayout rootView = holder.getView(R.id.root_view);
        if (!TextUtils.isEmpty(mTranstime)) {
            transtime.setText(CommonUtils.formatDateToString(CommonUtils
                    .formatStringToDate(listBean.getTransTime(), "yyyyMMddHHmmss"), "yyyy-MM-dd HH:mm:ss"));
        } else {
            transtime.setText("");
        }

        if (mStatus == BillConstant.STATUS_SUCCESS) {
            rootView.setBackgroundResource(R.drawable.shape_billitembg_success);
            transStatus.setText(mContext.getResources().getString(R.string.status_success));
            transStatus.setTextColor(mContext.getResources().getColor(R.color.colorGreen));
        } else if (mStatus == BillConstant.STATUS_FAILED) {
            rootView.setBackgroundResource(R.drawable.shape_billitembg_fail);
            transStatus.setText(mContext.getResources().getString(R.string.status_fail));
            transStatus.setTextColor(mContext.getResources().getColor(R.color.colorRed));
        } else if (mStatus == BillConstant.STATUS_PROCESSING) {
            rootView.setBackgroundResource(R.drawable.shape_billitembg_processing);
            transStatus.setText(mContext.getResources().getString(R.string.status_proce));
            transStatus.setTextColor(mContext.getResources().getColor(R.color.colorBlue));
        }

        if (mTradeType == BillConstant.TRAD_TYPE_WEIPAY || mTradeType == BillConstant.TRAD_TYPE_WECHATSCANPAY) {
            tr_trans_type.setText(mContext.getResources().getString(R.string.trade_weipay));
        } else if (mTradeType == BillConstant.TRAD_TYPE_ALIPAY || mTradeType == BillConstant.TRAD_TYPE_ALISCANPAY) {
            tr_trans_type.setText(mContext.getResources().getString(R.string.trade_alipay));
        } else if (mTradeType == BillConstant.TRAD_TYPE_UNINONLINE) {
            tr_trans_type.setText(mContext.getResources().getString(R.string.trade_uninonline));
        } else if (mTradeType == BillConstant.TRAD_TYPE_UNINONQUICK) {
            tr_trans_type.setText(mContext.getResources().getString(R.string.trade_uninonquick));
        } else if (mTradeType == BillConstant.TRAD_TYPE_UNINOSCANNER) {
            tr_trans_type.setText(mContext.getResources().getString(R.string.trade_uninonscanner));
        } else if (mTradeType == BillConstant.TRAD_TYPE_QQWALLET) {
            tr_trans_type.setText(mContext.getResources().getString(R.string.trade_qqwallet));
        }
        if (TextUtils.isEmpty(mSerialNumber) || "null".equals(mSerialNumber)) {
            trTransSn.setText("");
        } else {
            trTransSn.setText(mSerialNumber);
        }
        cardNoOut.setText(CommonUtils.formattingCard(mCardNoOut));
        tv_total.setText(CommonUtils.formatMoney(mTotal / 100));
    }
}
